package smlab.graphics
{
	import flash.display.Sprite;

	/**
	 * 绘制多边形
	 * @author simon
	 * 
	 */
	public class DrawPolygon extends Sprite
	{
		public function DrawPolygon()
		{
			super();
		}
		
		/**
		 * 
		 * @param n       边数量
		 * @param color   颜色
		 * @return 
		 * 
		 */
		public static function draw(n:int,color:uint=0):Sprite{
			var _sprite:Sprite = new Sprite;
		   _sprite.mouseEnabled = false;
		   _sprite.graphics.lineStyle (1, 0, 0);
		   _sprite.graphics.beginFill (Math.random ()*color);
		   _sprite.graphics.moveTo(Math.cos (Math.PI*2)*100, Math.sin (Math.PI*2)*100);
		   var _v:uint = n;
		   while (n--) {
		    _sprite.graphics.lineTo(Math.cos (n/_v*Math.PI*2) * 100, Math.sin (n/_v*Math.PI*2) * 100);
		   }
		   _sprite.graphics.endFill ();
		   return _sprite;
		}
		
	}
}